package com.abp.controller;

import com.abp.entity.UserCluster;
import com.abp.service.UserClusterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/user-clusters")
public class UserClusterController {

    @Autowired
    private UserClusterService userClusterService;

    // 获取所有用户聚类
    @GetMapping
    public List<UserCluster> getAllUserClusters() {
        return userClusterService.list();
    }

    // 根据用户ID获取聚类信息
    @GetMapping("/{id}")
    public UserCluster getUserClusterById(@PathVariable int id) {
        return userClusterService.getById(id);
    }

    // 新增用户聚类
    @PostMapping
    public boolean addUserCluster(@RequestBody UserCluster userCluster) {
        return userClusterService.save(userCluster);
    }

    // 更新用户聚类
    @PutMapping("/{id}")
    public boolean updateUserCluster(@PathVariable int id, @RequestBody UserCluster userCluster) {
        userCluster.setUserId(id);
        return userClusterService.updateById(userCluster);
    }

    // 删除用户聚类
    @DeleteMapping("/{id}")
    public boolean deleteUserCluster(@PathVariable int id) {
        return userClusterService.removeById(id);
    }
}
